#include <math.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdlib.h>
#include <time.h>
#include <process.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/mman.h>


void* do_proc (void *arg)
{
	char buffer [80];
	int i = 1;
	FILE *fp = (FILE *) arg;


	if (fp != NULL) {
		while (fgets (buffer, 80, fp) != NULL) {
            printf ("string %d: %s", i++, buffer);

        }
	} else {
		printf ("can't open\n");
	}

	return NULL;	
}



main (int argc,char *argv[])
{
	FILE *fp;
	pthread_t thread_id;

	fp = popen ("ls /", "r");

	printf ("starting\n--------\n");
	pthread_create (&thread_id, NULL, do_proc, (void *) fp);
	pthread_join (thread_id, NULL);	
	printf ("exiting\n\n");
	fflush (stdout);

	pclose (fp);

}
